{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAABECAYAAACmjMM7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAACPElEQVR4nO3ZMYoTUQDG8ZdNSAJZdr1FzmApeBl7QVAP4DE8glhoIWxn4RFi5xViwJhMMhaxy2ZB/F7eEn6/dhj4qvnPmxn0fV8A4H9dtR4AwGUQFAAiBAWACEEBIGJ06sJ8Pu/KITjL880B4JG7KaXsF4vFUT9OBqUcYjKYTsa31WY1tutaL6irG+1bT6jqerBpPaGa1W7WekJV3XrVekJV09mk9YRqtuuulBNftx4KynI6Gd++fvWiyqjH4PuXyz583T3/0XpCVXdP3reeUM3Tr59bT6jq27tnrSdU9ebjy9YTqvnw9lPZrrt7H57+oQAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkCEoAAQISgARAgKABGCAkDEoO/7ey/M5/N9KWUwnYzPu+iMdl3rBXV1o33rCVVdDzatJ1Sz2s1aT6iqW69aT6hqOpu0nlDNdt2VUkq/WCyODiSjB+7bl1Ku1r83y1rDqGzXekBdPy/6gP2r9YCqhsNh6wlV/X3oXqqbcujDkZMnFAD4F5f8igfAGQkKABGCAkCEoAAQISgARPwB8K5NVoTYsCUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x72 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import math\n",
    "import matplotlib.ticker as ticker\n",
    "import statsmodels.formula.api as smf\n",
    "from pprint import pprint\n",
    "import re as re\n",
    "\n",
    "from statsmodels.regression.mixed_linear_model import MixedLMResults\n",
    "\n",
    "import scipy as sp\n",
    "#from scipy.stats import nanmean\n",
    "#from scipy.stats import nanstd\n",
    "import copy\n",
    "import scipy.stats as stats\n",
    "import string\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.cm as cm\n",
    "from pprint import pprint\n",
    "import seaborn as sns\n",
    "sns.set(style=\"white\", context=\"talk\")\n",
    "custom_palette = [ \"greyish\", \"dusty purple\", \"greenish\", \"amber\", \"windows blue\", \"black\",\"faded green\"]  \n",
    "                     #\"green blue\", \"dull green\", \"faded green\",  \n",
    "sns.set_palette(sns.xkcd_palette(custom_palette))\n",
    "current_palette = sns.color_palette()\n",
    "%matplotlib inline\n",
    "sns.palplot(current_palette)\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "round_data = pd.read_csv('./all_studies_round_data.csv')\n",
    "\n",
    "round_data['group'] = 1 #this is only for the crossed mixed effect model\n",
    "\n",
    "game_rounds = pd.read_csv('./all_studies_game_data.csv')\n",
    "#round_data = round_data[round_data.round_index > 3]\n",
    "#print(round_data.size)\n",
    "conditions = ['dynamic_full_feedback',\n",
    "              'dynamic',         \n",
    "              'dynamic_self_feedback',\n",
    "              'dynamic_no_feedback',\n",
    "              'static',\n",
    "              'solo_feedback',\n",
    "              'solo_no_feedback'\n",
    "             ]\n",
    "\n",
    "\n",
    "colors ={'dynamic_no_feedback':'#196FFF',\n",
    "         'dynamic_self_feedback':'#000000',\n",
    "         'dynamic_full_feedback':'#E89468',\n",
    "         'dynamic': '#81B200',\n",
    "         'static':'#9B59B6',\n",
    "         'solo_feedback': '#95A5A6',\n",
    "         'solo_no_feedback': '#95A5A6'\n",
    "        }\n",
    "\n",
    "\n",
    "linestyles ={'dynamic_no_feedback':'-.',\n",
    "         'dynamic_self_feedback':':',\n",
    "         'dynamic_full_feedback':'-',\n",
    "         'dynamic': '-',\n",
    "         'static':'--',\n",
    "         'solo_feedback': '-',\n",
    "         'solo_no_feedback': '-'\n",
    "        }\n",
    "\n",
    "markers ={'dynamic_no_feedback':'d',\n",
    "         'dynamic_self_feedback':'^',\n",
    "         'dynamic_full_feedback':'p',\n",
    "         'dynamic': 'o',\n",
    "         'static':'*',\n",
    "         'solo_feedback': 'H',\n",
    "         'solo_no_feedback': 'h'\n",
    "        }\n",
    "\n",
    "#markers = ['s','o','*']\n",
    "#linestyles = ['--','-',':','-.']\n",
    "tick_size = 25\n",
    "label_size = 35\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "studies = [1,2]\n",
    "#crossed model with no independent groups https://stackoverflow.com/questions/50052421/mixed-models-with-two-random-effects-statsmodels\n",
    "# this is used as a variance component for the individual level stuff\n",
    "vcf = {\"player_id\": \"0 + C(player_id)\", \"game_id\": \"0 + C(game_id)\"} \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Statistical Tests for study 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S1: Solo vs Static (individual)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "solo vs static (individual): over all\n",
      " β:  -0.05590339996708633 , t-statistic -4.62391442379746 , pvalue  3.765652717457147e-06  ci  -0.07959948092933777 -0.03220731900483489 reduced error by  -28.503128750347077\n",
      "=============================\n",
      "solo vs static (individual): first half\n",
      " β:  -0.05099855368097738 , t-statistic -3.385275465027136 , pvalue  0.0007110685716441642  ci  -0.08052505145375081 -0.02147205590820395 reduced error by  -26.789866111665937\n",
      "=============================\n",
      "solo vs static (individual): second half\n",
      " β:  -0.0608151390168452 , t-statistic -3.2852069016354104 , pvalue  0.0010190750789004176  ci  -0.09709762768703412 -0.024532650346656283 reduced error by  -30.127750556294234\n",
      "=============================\n",
      "solo vs static (individual): adapted periods\n",
      " β:  -0.056947868161805124 , t-statistic -5.226517529439821 , pvalue  1.727324500467752e-07  ci  -0.07830353567172281 -0.03559220065188744 reduced error by  -32.59577062475157\n"
     ]
    }
   ],
   "source": [
    "#### Study 1 Solo vs Static\n",
    "\n",
    "print(\"solo vs static (individual): over all\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'dynamic') &\n",
    "                  (round_data.revised_error.notnull())]\n",
    "\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - data[data.condition == 'solo_feedback'].revised_error.mean() ) / data[data.condition == 'static'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"solo vs static (individual): first half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'dynamic') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.half==1)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - data[data.condition == 'solo_feedback'].revised_error.mean() ) / data[data.condition == 'static'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"solo vs static (individual): second half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'dynamic') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.half==2)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - data[data.condition == 'solo_feedback'].revised_error.mean() ) / data[data.condition == 'static'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"solo vs static (individual): adapted periods\")\n",
    "forumla = \"revised_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'dynamic') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_error.mean() - data[data.condition == 'solo_feedback'].revised_error.mean() ) / data[data.condition == 'static'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S1: Solo vs Static (Group)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "solo vs static (group): over all\n",
      " β:  -0.045274688755688665 , t-statistic -7.031058610606564 , pvalue  2.0497237210728344e-12  ci  -0.057895371399202436 -0.032654006112174894 reduced error by  -28.2985764233299\n",
      "=============================\n",
      "solo vs static (group): first half\n",
      " β:  -0.04030900011099926 , t-statistic -5.536935344755031 , pvalue  3.0781011574815904e-08  ci  -0.05457757713984571 -0.02604042308215282 reduced error by  -26.114027853710592\n",
      "=============================\n",
      "solo vs static (group): second half\n",
      " β:  -0.05024037740037788 , t-statistic -6.059510188310383 , pvalue  1.3653667989108753e-09  ci  -0.06649075527157965 -0.03398999952917611 reduced error by  -30.33456202851823\n",
      "=============================\n",
      "solo vs static (group): adapted periods\n",
      " β:  -0.043781866189367205 , t-statistic -6.572089581670327 , pvalue  4.96139965178391e-11  ci  -0.05683873034813334 -0.03072500203060107 reduced error by  -31.182033320777926\n"
     ]
    }
   ],
   "source": [
    "#### Study 1 Solo vs Static\n",
    "\n",
    "print(\"solo vs static (group): over all\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'dynamic')]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_wisdom_error.mean() - data[data.condition == 'solo_feedback'].revised_wisdom_error.mean() ) / data[data.condition == 'static'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"solo vs static (group): first half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'dynamic')&\n",
    "                   (game_rounds.half==1)\n",
    "                  ]\n",
    "\n",
    "\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_wisdom_error.mean() - data[data.condition == 'solo_feedback'].revised_wisdom_error.mean() ) / data[data.condition == 'static'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"solo vs static (group): second half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'dynamic') &\n",
    "                  (game_rounds.half==2)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_wisdom_error.mean() - data[data.condition == 'solo_feedback'].revised_wisdom_error.mean() ) / data[data.condition == 'static'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"solo vs static (group): adapted periods\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('solo_feedback'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'dynamic') &\n",
    "                  (game_rounds.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'static'].revised_wisdom_error.mean() - data[data.condition == 'solo_feedback'].revised_wisdom_error.mean() ) / data[data.condition == 'static'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S1: Static vs Dynamic (individual)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "static vs dynamic (individual): over all\n",
      " β:  -0.03774506409512676 , t-statistic -4.6436019970804985 , pvalue  3.4238684100355427e-06  ci  -0.05367643940832459 -0.021813688781928936 reduced error by  -16.817912328325743\n",
      "=============================\n",
      "static vs dynamic: first half\n",
      " β:  -0.03753281968301293 , t-statistic -3.8686134974161375 , pvalue  0.00010945598471044681  ci  -0.05654815291960387 -0.018517486446421993 reduced error by  -21.013423885053506\n",
      "=============================\n",
      "static vs dynamic (individual): second half\n",
      " β:  -0.0367214336802311 , t-statistic -3.169763853087982 , pvalue  0.0015256287261661103  ci  -0.05942744296348207 -0.014015424396980131 reduced error by  -13.113329240234716\n",
      "=============================\n",
      "static vs dynamic (individual): adapted periods\n",
      " β:  -0.05328092687490666 , t-statistic -6.555546720448231 , pvalue  5.543838844989161e-11  ci  -0.06921074969380178 -0.03735110405601154 reduced error by  -35.72598333131\n"
     ]
    }
   ],
   "source": [
    "#### Study 1 Static vs Dynamic\n",
    "\n",
    "print(\"static vs dynamic (individual): over all\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('static'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'solo_feedback') &\n",
    "                  (round_data.revised_error.notnull())]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - data[data.condition == 'static'].revised_error.mean() ) / data[data.condition == 'dynamic'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"static vs dynamic: first half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('static'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'solo_feedback') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.half==1)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - \n",
    "                 data[data.condition == 'static'].revised_error.mean() ) / data[data.condition == 'dynamic'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"static vs dynamic (individual): second half\")\n",
    "\n",
    "forumla = \"revised_error ~ C(condition, Treatment('static'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'solo_feedback') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.half==2)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - data[data.condition == 'static'].revised_error.mean() ) / data[data.condition == 'dynamic'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"static vs dynamic (individual): adapted periods\")\n",
    "forumla = \"revised_error ~ C(condition, Treatment('static'))\"\n",
    "data = round_data[(round_data.study==1) &\n",
    "                  (round_data.condition != 'solo_feedback') &\n",
    "                  (round_data.revised_error.notnull()) &\n",
    "                  (round_data.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups='group',\n",
    "                    vc_formula=vcf,re_formula=\"0\").fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_error.mean() - data[data.condition == 'static'].revised_error.mean() ) / data[data.condition == 'dynamic'].revised_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Table S1: Static vs Dynamic (Group)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "static vs dynamic (group): over all\n",
      " β:  -0.03058689404913712 , t-statistic -3.2547670891874247 , pvalue  0.0011348539389613855  ci  -0.04900578827183187 -0.012167999826442375 reduced error by  -17.939577047710912\n",
      "=============================\n",
      "static vs dynamic (group): first half\n",
      " β:  -0.028566450790567764 , t-statistic -2.4585553702671272 , pvalue  0.01394972635470743  ci  -0.05133966769377919 -0.005793233887356336 reduced error by  -20.263780759173873\n",
      "=============================\n",
      "static vs dynamic (group): second half\n",
      " β:  -0.02942021162712377 , t-statistic -2.2244684708334828 , pvalue  0.02611694153403022  ci  -0.05534215925765307 -0.0034982639965944716 reduced error by  -15.852881091865834\n",
      "=============================\n",
      "static vs dynamic (group): adapted periods\n",
      " β:  -0.04301241694950593 , t-statistic -4.441208783157885 , pvalue  8.945494848385462e-06  ci  -0.061994363582762155 -0.0240304703162497 reduced error by  -39.57518431774202\n"
     ]
    }
   ],
   "source": [
    "#### Study 1 Static vs Dynamic\n",
    "\n",
    "print(\"static vs dynamic (group): over all\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('static'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'solo_feedback')]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_wisdom_error.mean() - data[data.condition == 'static'].revised_wisdom_error.mean() ) / data[data.condition == 'dynamic'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"static vs dynamic (group): first half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('static'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'solo_feedback') &\n",
    "                  (game_rounds.half==1)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_wisdom_error.mean() - data[data.condition == 'static'].revised_wisdom_error.mean() ) / data[data.condition == 'dynamic'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "\n",
    "print(\"static vs dynamic (group): second half\")\n",
    "\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('static'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'solo_feedback') &\n",
    "                  (game_rounds.half==2)\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_wisdom_error.mean() - data[data.condition == 'static'].revised_wisdom_error.mean() ) / data[data.condition == 'dynamic'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')\n",
    "#print(model.summary())\n",
    "\n",
    "\n",
    "print('=============================')\n",
    "\n",
    "print(\"static vs dynamic (group): adapted periods\")\n",
    "forumla = \"revised_wisdom_error ~ C(condition, Treatment('static'))\"\n",
    "data = game_rounds[(game_rounds.study==1) &\n",
    "                  (game_rounds.condition != 'solo_feedback') &\n",
    "                  (game_rounds.quarter.isin([2,4]))\n",
    "                 ]\n",
    "model = smf.mixedlm(forumla,data=data,groups=data['game_id']).fit(method='powell')\n",
    "\n",
    "reduced_error = (data[data.condition == 'dynamic'].revised_wisdom_error.mean() - data[data.condition == 'static'].revised_wisdom_error.mean() ) / data[data.condition == 'dynamic'].revised_wisdom_error.mean()\n",
    "\n",
    "print(\" β: \",model.params[1], ', t-statistic',model.tvalues[1], ', pvalue ', model.pvalues[1], \n",
    "      ' ci ', model.conf_int()[0][1], model.conf_int()[1][1], 'reduced error by ', reduced_error*100)#print (' ---- ')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
